import { Controller, Get, Post,Put, Body, Patch,Query, Param, Delete, Headers } from '@nestjs/common';
import { SessionService } from './session.service';
import { ApiTags } from '@nestjs/swagger';
import {SessionDto} from './dto/session.dto'
import { isNoAuth } from 'src/utils/decorator/jwt.decorator';
@ApiTags('会话Session')
@Controller('session')
@isNoAuth()
export class SessionController {
  constructor(private readonly sessionService: SessionService) {}

  @Post("add")
  create(@Headers() header,@Body() sessionDto: SessionDto) {
    const dto = {...sessionDto, time: Date.now(), userId: header.userid }
    return this.sessionService.create(dto);
  }

  @Get("search")
  async findOne(@Query() query):Promise<SessionDto[]> {
    return  await this.sessionService.findOne(query.sessionName, query.id);
  }

  @Put('update/:id')
  update(@Param() param, @Body() sessionDto: SessionDto) {
    return this.sessionService.update(param.id, sessionDto);
  }

  @Delete('del')
  remove(@Query() query):Promise<string> {
    return this.sessionService.remove(query.id);
  }

  @Get('list')
  list(@Headers() header, @Query() query):Promise<any> {
    return this.sessionService.list(query.page,query.pageSize,header.userid);
  }
}
